#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

#define buttonPin D3

ESP8266WiFiMulti wifimulti;

bool buttonstate;
float floatV;
int intV;

const char *host = "192.168.0.150";
const int httpPort = 80;

void setup(void)
{
    Serial.begin(115200);
    //在这里添加你需要的WiFi账号密码
    wifimulti.addAP("LAGRANGE", "abcdef..");
    wifimulti.addAP("OpenWRT-2.4G", "skabcdef");
    wifimulti.addAP("MEIZU 16s Pro", "skabcdef");
    wifimulti.addAP("Feng", "1234567890");

    Serial.println("\n");

    Serial.print("WiFi Connecting ...");
    while (wifimulti.run() != WL_CONNECTED)
    {
        delay(250);
        Serial.print(".");
    }
    Serial.print("WiFi Connected!");

    Serial.println(WiFi.SSID());
    Serial.println(WiFi.localIP());

    pinMode(buttonPin, INPUT_PULLUP);
}

void loop(void)
{

    buttonstate = digitalRead(buttonPin);
    floatV += 1.5;
    intV += 1;

    wifiClientRequest();

    delay(500);
}

void wifiClientRequest()
{
    WiFiClient client;

    String url = "/update?float=" + String(floatV) +
                 "&int=" + String(intV) +
                 "&button=" + String(buttonstate);

    String httpRequest = String("GET ") + url + " HTTP/1.1\r\n" +
                         "Host: " + host + "\r\n" +
                         "Connection：close\r\n" +
                         "\r\n";

    Serial.print("Connecting to ");
    Serial.println(host);

    if (client.connect(host, httpPort))
    {
        Serial.println("Sucess");

        client.print(httpRequest);
        Serial.println("Sending request: ");
        Serial.println(httpRequest);
    }
    else
        Serial.println("Failed!");
    client.stop();
    while(digitalRead(buttonPin));
}